package vista;
import java.awt.BorderLayout;
import java.awt.event.ActionListener;
import java.util.Vector;
import javax.swing.ComboBoxModel;
import javax.swing.DefaultComboBoxModel;
import javax.swing.JButton;
import javax.swing.JComboBox;
import javax.swing.JLabel;

import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTable;
import javax.swing.JTextField;

import javax.swing.JOptionPane;
import javax.swing.WindowConstants;
import javax.swing.SwingUtilities;
import javax.swing.table.DefaultTableModel;
import javax.swing.table.TableModel;

/**
* This code was edited or generated using CloudGarden's Jigloo
* SWT/Swing GUI Builder, which is free for non-commercial
* use. If Jigloo is being used commercially (ie, by a corporation,
* company or business for any purpose whatever) then you
* should purchase a license for each developer using Jigloo.
* Please visit www.cloudgarden.com for details.
* Use of Jigloo implies acceptance of these licensing terms.
* A COMMERCIAL LICENSE HAS NOT BEEN PURCHASED FOR
* THIS MACHINE, SO JIGLOO OR THIS CODE CANNOT BE USED
* LEGALLY FOR ANY CORPORATE OR COMMERCIAL PURPOSE.
*/
public class VentanaTematica extends javax.swing.JFrame {
	private JPanel panTematica;
	private JTextField txtNombre;
	private JComboBox cmbLinea;
	private JLabel lblLinea;
	private JLabel lblCod;
	private JLabel lblNombre;
	private JButton btnCrear;
	private JButton btnGuardar;
	private JButton btnSalir;
	private JTextField txtCod;
	private JLabel lblTitulo;
	private JLabel lblTematicas;
	private JTable tblTematicas;
	private JScrollPane srcTematicas;

	
	private static VentanaTematica instancia;

	public static  VentanaTematica getInstancia() {
		if (instancia == null)
			instancia = new VentanaTematica();
		else
			instancia.setTitle("Tematicas");
		return instancia;
	}
	
	
	public VentanaTematica() {
		super();
		initGUI();
	}
	
	private void initGUI() {
		try {
			setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
			{
				panTematica = new Fondo("imagen.jpg");
				getContentPane().add(panTematica, BorderLayout.CENTER);
				panTematica.setLayout(null);
				panTematica.setPreferredSize(new java.awt.Dimension(565, 351));
				{
					srcTematicas = new JScrollPane();
					panTematica.add(srcTematicas);
					srcTematicas.setBounds(29, 92, 461, 252);
					{
						DefaultTableModel tblTematicasModel = 
								new DefaultTableModel(
										new String[][] {},
										new String[] { "Codigo", "Nombre", "Linea de Investigacion" });
						tblTematicas = new JTable();
						srcTematicas.setViewportView(tblTematicas);
						tblTematicas.setModel(tblTematicasModel);
					}
				}
				{
					lblTematicas = new JLabel();
					panTematica.add(lblTematicas);
					lblTematicas.setText("Tematicas Registradas");
					lblTematicas.setBounds(29, 52, 171, 19);
					lblTematicas.setFont(new java.awt.Font("URW Palladio L",0,16));
				}
				{
					lblTitulo = new JLabel();
					panTematica.add(lblTitulo);
					lblTitulo.setText("TEMATICAS");
					lblTitulo.setBounds(355, 12, 125, 31);
					lblTitulo.setFont(new java.awt.Font("URW Palladio L",0,20));
				}
				{
					txtCod = new JTextField();
					panTematica.add(txtCod);
					txtCod.setBounds(606, 92, 142, 22);
				}
				{
					txtNombre = new JTextField();
					panTematica.add(txtNombre);
					txtNombre.setBounds(606, 134, 142, 22);
				}
				{
					btnSalir = new JButton();
					panTematica.add(btnSalir);
					btnSalir.setText("Salir");
					btnSalir.setBounds(716, 376, 117, 22);
				}
				{
					btnGuardar = new JButton();
					panTematica.add(btnGuardar);
					btnGuardar.setText("Guardar");
					btnGuardar.setBounds(716, 333, 117, 22);
				}
				{
					btnCrear = new JButton();
					panTematica.add(btnCrear);
					btnCrear.setText("Crear");
					btnCrear.setBounds(355, 376, 135, 22);
				}
				{
					lblNombre = new JLabel();
					panTematica.add(lblNombre);
					lblNombre.setText("Nombre:");
					lblNombre.setBounds(527, 136, 79, 19);
					lblNombre.setFont(new java.awt.Font("URW Palladio L",0,16));
				}
				{
					lblCod = new JLabel();
					panTematica.add(lblCod);
					lblCod.setText("Codigo:");
					lblCod.setBounds(527, 91, 79, 24);
					lblCod.setFont(new java.awt.Font("URW Palladio L",0,16));
				}
				{
					lblLinea = new JLabel();
					panTematica.add(lblLinea);
					lblLinea.setText("Linea de Investigacion a la que Pertenece:");
					lblLinea.setBounds(527, 180, 306, 22);
					lblLinea.setFont(new java.awt.Font("URW Palladio L",0,16));
				}
				{
					ComboBoxModel cmbLineaModel = 
							new DefaultComboBoxModel(
									new String[] {});
					cmbLinea = new JComboBox();
					panTematica.add(cmbLinea);
					cmbLinea.setModel(cmbLineaModel);
					cmbLinea.setBounds(626, 219, 207, 22);
				}
			}
			pack();
			this.setSize(866, 442);
		} catch (Exception e) {
		    //add your error handling code here
			e.printStackTrace();
		}
	}
	
	// SETTERS Y GETTERS
	public String getTxtNombre() {
		return txtNombre.getText();
	}

	public void setTxtNombre(String txtNombre) {
		this.txtNombre.setText(txtNombre);
	}

	public String getTxtCod() {
		return txtCod.getText();
	}

	public void setTxtCod(String txtCod) {
		this.txtCod.setText(txtCod);
	}
	
	public String getCmbLinea() {
		return (String)cmbLinea.getSelectedItem();
	}

	public void setCmbLinea(String cmbLinea) {
		this.cmbLinea.addItem(cmbLinea);
	}

	//LISTENERS
	public void agregarListener(ActionListener action){
		btnCrear.addActionListener(action);
		btnGuardar.addActionListener(action);
		btnSalir.addActionListener(action);
	}
	
	//METODO MOSTRAR MENSAJE
	public void mostrarMensaje(String mensaje) {
		JOptionPane.showMessageDialog(this, mensaje);
		}
	
	//METODO COMPONENTES INVISIBLES
	public void componentesHabilitados(boolean valor){
		txtCod.setVisible(valor);
		txtNombre.setVisible(valor);
		lblCod.setVisible(valor);
		lblNombre.setVisible(valor);
		cmbLinea.setVisible(valor);
		lblLinea.setVisible(valor);
		btnGuardar.setVisible(valor);
		}
	
	//METODO DESHABILITAR EDICION
		public void desahabilitarComponente(boolean valor){
			txtCod.setEditable(valor);
			}
	
	//METODO AGRGAR LINEA DEL COMBO
		public void agregarLineacmb(String line) {
			DefaultComboBoxModel modelocombo = (DefaultComboBoxModel) cmbLinea.getModel();
			modelocombo.addElement(line);

		}
		
	// METODO CARGAR LISTADO TEMATICAS REGISTRADAS
	public void cargarListado(Vector<String> lineas){
		DefaultTableModel tbl = (DefaultTableModel) this.tblTematicas.getModel();
		tbl.addRow(lineas);
	}
}
